﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Controls;

namespace Knowledgecast.Twitter.WPF
{
    public class StatusInfoConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            List<Inline> inlines = new List<Inline>();
            string username = value as string;

            int spaceIndex = username.IndexOf(' ');
            if (spaceIndex > 0)
            {
                username = username.Substring(0, spaceIndex);
            }

            string linkUrl = "http://www.twitter.com/" + username;

            Hyperlink link = new Hyperlink();            
            link.Inlines.Add(new Run(username));
            link.NavigateUri = new Uri(linkUrl, UriKind.Absolute);
            link.Command = TwitterCommands.ShowUrl;
            link.CommandParameter = linkUrl;

            inlines.Add(link);

            return inlines;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
